package com.dodo.blog.ui.component.composite;

import com.dodo.blog.ui.component.HtmlComponent;
import com.dodo.blog.ui.component.Unit;
import com.dodo.blog.ui.component.container.Panel;

import java.text.MessageFormat;
import java.util.List;

/**
 * @author <a href="mailto:pohorelec@comvai.com">Jozef Pohorelec</a>
 */
public class MultiColumn
        extends Panel
{
    private static final long serialVersionUID = 1L;

    public MultiColumn( List<HtmlComponent> components, int gap, int width, Unit unit )
    {
        setStyle( "overflow:hidden;" );
        int i = 0;
        for ( HtmlComponent component : components )
        {
            if ( i == components.size() - 1 )
            {
                gap = 0;
            }

            component.setStyle( MessageFormat.format( "margin-right:{0}{1};", gap, unit.getValue() ) );

            Panel column = new Panel();
            column.setClassName( "multi-column-item" );
            column.setStyle( MessageFormat.format( "float:left;width:{0}{1};", width, unit.getValue() ) );
            column.add( component );
            add( column );
            i++;
        }
    }
}